package tests;

import static org.junit.Assert.*;

import gameTheory.MixedProfileGenerator;
import graphs.Graph;

import java.util.ArrayList;
import java.util.List;

import model.Junction;
import model.Road;

import org.junit.Test;

public class testMixedStrategyProbGenerator {
	private List<Double[]> sollutions;
	
	@Test
	public void test() {
		generateSollutions();
		
		List<double[]> strategyProbs = new ArrayList<double[]>();
		MixedProfileGenerator.resolution = 2;
		MixedProfileGenerator gen = new MixedProfileGenerator(getGraph());
		
		gen.fillStrategyProbs(strategyProbs);
		for(int i = 0 ; i < strategyProbs.size() ; i++){
			double[] probs = strategyProbs.get(i);
			for(int j = 0 ; j < probs.length ; j++)
				System.out.print(probs[j] + ",");
		}
		
		assertTrue("size="+strategyProbs.size(), strategyProbs.size() == 5);
		for (double[] integers : strategyProbs) {
			assertTrue(hasSollution(integers));
		}
	}
	
	private void generateSollutions() {
		sollutions = new ArrayList<Double[]>();
		sollutions.add(new Double[]{1.0,0.0});
		sollutions.add(new Double[]{0.75,0.25});
		sollutions.add(new Double[]{0.5,0.5});
		sollutions.add(new Double[]{0.25,0.75});
		sollutions.add(new Double[]{0.0,1.0});
	}

	private boolean hasSollution(double[] integers) {
		for (Double[] sol : sollutions) {
			boolean equals = true;
			if(sol.length != integers.length)
				return false;
			for (int i = 0 ; i < sol.length ; i++) {
				System.out.print(sol[i]+",");
				equals = (sol[i].equals(integers[i])) & equals;
			}
			System.out.println();
			if(equals)
				return equals;
		}
		return false;
	}

	private Graph getGraph(){
		final Junction start = new Junction();
		final Junction end = new Junction();
		
		new Road(start,end, "A", 10, 10);
		new Road(start,end, "B", 10, 10);
		
		Graph g = new Graph() {
			@Override
			public Junction getStart() {
				return start;
			}
			@Override
			public Junction getEnd() {
				return end;
			}
		};
		
		return g;
	}

}
